﻿using System;
using System.Web.UI;
using System.Threading;
using Business;
using System.Text;
using System.IO;

namespace TimeWork.report.general
{
    public partial class TimeCumulative : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["email"] == null)
            {
                Response.Redirect("http://"+Request.Url.Authority+"/Login.aspx");
            }
        }

        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            ltrData.Text = String.Empty;
            Thread.Sleep(500);
            int level = Int32.Parse(ddlCode.SelectedValue);

    
            int month = Int32.Parse(ddlMonth.SelectedValue);
            int year = Int32.Parse(ddlYear.SelectedValue);
            ltrData.Text = BuReport.repTimeCumulative(month, year, level, cbIsChild.Checked, Session["companyid"].ToString());

        }

        public override void VerifyRenderingInServerForm(Control control)
        {
            return;
        }
        protected void btnExportExcel_Click(object sender, ImageClickEventArgs e)
        {
            Response.Clear();
            Response.Buffer = true;
            Response.AppendHeader("Content-Disposition", "attachment;filename=BaoCaoSanPhamCongDon" + DateTime.
            Now.ToString("yyyyMMdd") + ".xls");
            Response.ContentEncoding = System.Text.Encoding.UTF8;
            Response.ContentType = "application/ms-excel";
            this.EnableViewState = false;

            var sb = new StringBuilder();
            ltrData.RenderControl(new HtmlTextWriter(new StringWriter(sb)));
            Response.Write(sb.ToString());
            Response.End();
        }
    }
}